package com.exigenservices.demenkov.utils;

import com.exigenservices.demenkov.model.domain.News;

import java.util.Comparator;

/**
 * Comparator for News that compare it by date and time
 *
 * @Author DemYura
 * @Date 26.11.11
 */
public class NewsComparatorByDateAndTime implements Comparator<News> {
    @Override
    public int compare(News o1, News o2) {
        if (o1.getYear() - o2.getYear() != 0) {
            return o1.getYear() - o2.getYear();
        } else {
            if (o1.getMonth() - o2.getMonth() != 0) {
                return o1.getMonth() - o2.getMonth();
            } else {
                if (o1.getDay() - o2.getDay() != 0) {
                    return o1.getDay() - o2.getDay();
                } else {
                    if (o1.getTime().compareTo(o2.getTime()) != 0) {
                        return o2.getTime().compareTo(o1.getTime());
                    } else {
                        return (int) (o2.getId() - o1.getId());
                    }
                }
            }
        }
    }
}